// pages/mine_center/comment/comment.js
const app = getApp();
var request = require("../../../utils/request.js");
var wx_alert = require("../../../utils/wx_alert.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    starts:[
      {
        select:true,
      },
      {
        select: true,
      },
      {
        select: true,
      },
      {
        select: true,
      },
      {
        select: true,
      },
    ],
    select_start:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var data = {
      orderId: options.order_id,
    }
    request.request(app.globalData.getOrderDetail, data, function (res) {
      console.log(res)
      if (res.code == 0) {
        that.setData({
          orderDetail: res.orderDetail,
          img_url: request.url + "/",
          productId: res.orderDetail.productId,
          orderId: options.order_id
        })
      }
    })
  },
  start_click: function (e) {
    var index = e.currentTarget.dataset.index;
    var starts = this.data.starts;
    starts[index].select = !starts[index].select;
    for (var i in starts){
      if(i <= index){
        starts[i].select = false;
      }else{
        starts[i].select = true
      }
    }
    this.setData({
      starts: starts,
      select_start:index+1
    })
  },
  comment_sure:function(){
    request.request(app.globalData.commentOrder, { orderId: this.data.orderId, productId: this.data.productId, num: this.data.select_start},function(res){
      console.log(res)
      if(res.code==0){
        wx_alert.alert("评价成功",function(){
          setTimeout(function(){
            wx.navigateBack({

            })
          },400)
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

})